﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Deflection
{
    class BackgroundManager
    {

        private static BackgroundManager instance = null;

        public List<Layer> layers = new List<Layer>();
        private Vector2 direction;

        

        public static BackgroundManager Instance()
        {
            if (instance == null)
            {
                instance = new BackgroundManager();
            }
            return instance;
        }

        private BackgroundManager()
        {
            direction = new Vector2(-1.0f, 0.0f);
            direction.Normalize();
            CreateLayers();   
        }

        public void Update(GameTime gameTime)
        {
            foreach (Layer layer in layers)
            {
                layer.Update(gameTime);
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            foreach (Layer layer in layers)
            {
                layer.Draw(gameTime, spriteBatch);
            }
        }

        public void CreateLayers()
        {
            float baseSpeed = 4.0f;
            float speedDifference = baseSpeed / 5;

            layers.Add(new Layer(baseSpeed, Color.Red, direction));
            layers.Add(new Layer(baseSpeed + (1 * speedDifference), Color.Blue, direction));
            layers.Add(new Layer(baseSpeed + (2 * speedDifference), Color.Green, direction));           
        }

        public void LoadContent(ContentManager content)
        {
            BackGroundElement.BackgroundSprite = GameObject.LoadContent(content, "Sprites/BGObject");   
        }
    }
}
